<?php

/*
	PIE Content Management System
	John Girata
	Licensed under the GNU General Public License version 3
*/

defined('PIESECVAR') or die('Restricted Access');

class com_home
{
	function __construct()
	{
		global $login, $controller, $db;
		
		// Check the user's login and permissions
		// NOTE: this class is called from inside ComponentHandler,
		// and $com is initialized after ComponentHandler is loaded,
		// so we cannot use the variable $com, and must access
		// the functions in ComponentHandler using ComponentHandler::
		if(!$login->get_login())
			ComponentHandler::fire_com('com.login');
		else
		{
			// Check the user's groups for a staff group
			$groups = $login->get_login_attr('groups');
			$staff = false;
			
			foreach($groups as $group)
			{
				$db->query("SELECT `staff` FROM `#__groups` WHERE `id`='$group' AND `staff`='1'");
				
				if($db->get_num_rows() > 0)
					$staff = true;
			}
			
			if(!$staff)
				ComponentHandler::fire_com('e403');
			else
			{
				$tmpl = file_get_contents(TMPL_DIR . 'com.home/com.home.tmpl');
				$controller->add_content($tmpl);
			}
		}
	}
}

$com_home = new com_home();

?>